package my.headfirstjava.observer.v2;

import java.util.ArrayList;
import java.util.List;

/**
 * author: xl
 * time: 2018/8/23 9:35
 * description:
 **/
public class Subject {


    List<Observer> list= new ArrayList<>();


    //预定
    public void add(Observer observer){
        list.add(observer);
    }

    //取消预定
    public void cancel(Observer observer){
        list.remove(observer);
    }


    public void notifyCurrentWeather(WeatherData msg){
        for (Observer observer:list){
            if(observer instanceof CurrentWeather ){
                observer.update(msg);
            }

        }
    }



    public void notifyForecastWeather(WeatherData msg){
        for (Observer observer:list){
            if(observer instanceof ForecastWeather ){
                observer.update(msg);
            }
        }
    }




}
